﻿using B.S.Domain;
using Microsoft.AspNetCore.SignalR;

namespace B.S.Data.MES.API
{
    /// <summary>
    /// SignalR Hub for Tel数据实时通信
    /// </summary>
    public class Hubtel : Hub
    {
        /// <summary>
        /// 发送Tel数据给所有客户端
        /// </summary>
        /// <param name="tel">Tel数据列表</param>
        /// <returns></returns>
        public Task SendMessage(List<Tel> tel)
        {
            return Clients.All.SendAsync("Tas", tel);
        }

        /// <summary>
        /// 客户端连接时调用
        /// </summary>
        /// <returns></returns>
        public override async Task OnConnectedAsync()
        {
            // 可以在这里记录连接信息或执行其他初始化操作
            await Clients.Caller.SendAsync("Connected", Context.ConnectionId);
            await base.OnConnectedAsync();
        }

        /// <summary>
        /// 客户端断开连接时调用
        /// </summary>
        /// <param name="exception">断开连接的异常信息</param>
        /// <returns></returns>
        public override async Task OnDisconnectedAsync(System.Exception exception)
        {
            // 可以在这里清理资源或记录断开连接信息
            await base.OnDisconnectedAsync(exception);
        }
    }
}
